<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <user-search :typeList="merchanApplyForStatusList"
                   @search="reload" />

      <el-drawer :visible.sync="drawer"
                 size="50%"
                 :before-close="handleClose"
                 ref="drawer"
                 :with-header="false">
        <incomingDetails :detailsList="viewDetailObject"></incomingDetails>
      </el-drawer>

      <!-- 数据表格 -->
      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection"
                     cache-key="systemUserTable">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <!-- <el-button size="small"
                     type="success"
                     icon="el-icon-plus"
                     class="ele-btn-icon"
                     v-if="currentPlatform !== '总平台'"
                     @click="openWeInbound(1)">
            微信进件
          </el-button>
          <el-button size="small"
                     type="primary"
                     icon="el-icon-plus"
                     class="ele-btn-icon"
                     v-if="currentPlatform !== '总平台'"
                     @click="openWeInbound(2)">
            支付宝进件
          </el-button> -->
        </template>
        <template v-slot:funcType="{ row }">
          <el-tag :type="row.funcType == '1' ? 'success' : ''">
            {{ applyForType(row.funcType) }}
          </el-tag>
        </template>
        <template v-slot:status="{ row }">
          <el-tag :type="merchanApplyForStatus(row.status).type">
            {{ merchanApplyForStatus(row.status).status }}
          </el-tag>
        </template>
        <template v-slot:action="{ row }">
          <el-link type="primary"
                   v-if="row.status == '3'"
                   :underline="false"
                   style="color: #00cc5c"
                   @click="electronicProtocolDownloadFn(row)">
            下载签约电子协议
          </el-link>
          <el-link type="primary"
                   v-if="row.status == '5'"
                   :underline="false"
                   style="color: #00cc5c"
                   @click="qianyue(row)">
            签约
          </el-link>
          <el-link type="primary"
                   v-if="row.status == '1'"
                   :underline="false"
                   style="color: #f5222d"
                   @click="statusFn(row)">
            驳回原因
          </el-link>
          <el-link type="primary"
                   v-if="row.status == '9'"
                   :underline="false"
                   :style="{ color: row.funcType == '1' ? '#00cc5c' : '#1890ff' }"
                   @click="statusFn(row)">
            处理进件
          </el-link>
          <el-link type="primary"
                   v-if="row.status == '0'"
                   :underline="false"
                   style="color: #00cc5c"
                   @click="viewDetail(row.id)">
            查看详情
          </el-link>
          <el-popconfirm class="ele-action"
                         title="是否确定要删除该笔进件信息"
                         @confirm="remove(row)">
            <template v-slot:reference>
              <el-link type="danger"
                       icno="el-icon-finished"
                       :underline="false"
                       icon="el-icon-delete">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 修改弹窗 -->
    <ele-modal width="600px"
               height="300px"
               :title="incomingStatus == '9' ? '设置商家进件费率' : '驳回原因'"
               :visible.sync="visibleModal"
               :maxable="true">
      <!-- class="SigningReminder" -->
      <div style="padding: 0 0 30px 0; line-height: 18px"
           v-if="incomingStatus == '9'">
        <!-- oninput="value=value.replace(/[^0-9]/g,'')" -->
        <el-input v-model.number="merchantHandlingCharge"
                  type="number"
                  maxlength="3"
                  @blur="(e) => inputChangeWx(e, merchantHandlingCharge)"
                  placeholder="请设置商家进件费率"
                  clearable><template v-slot:append>%</template></el-input>
      </div>
      <div v-else
           style="color: red">
        {{ currentlistInformation?.rejectReason }}
      </div>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="visibleModal = false">取 消</el-button>
        <el-button v-if="incomingStatus == '9'"
                   type="primary"
                   @click="
            visibleModalFn(merchantHandlingCharge, currentlistInformation)
          ">确定</el-button>
        <el-button v-if="incomingStatus == '1'"
                   type="primary"
                   @click="visibleModal = false">确定</el-button>
      </span>
    </ele-modal>
  </div>
</template>

<script>
import { getToken } from '@/utils/token-util';
import { userOssSignature } from '@/api/creatCenter/material';
import UserSearch from './components/user-search.vue';
import UserEdit from './components/user-edit.vue';
import UserImport from './components/user-import.vue';
import EquipmentEdit from './components/equipment-edit.vue';
import RegionsSelect from '@/components/RegionsSelect/index.vue';
import incomingDetails from './components/incomingDetails.vue';
import {
  wxGetUploadMediaId,
  wxSumbitMerchantApplyFor,
  zfbGetUploadMediaId,
  zfbMerchantCreate,
  merSigningApplicationo,
  electronicProtocolDownloadApi
} from '@/api/douApi';
import {
  pageMerchant,
  removeUsers,
  updateUserStatus,
  resetPassword,
  updateUserPassword,
  pageAgencyType
} from '@/api/oem';
import { JSEncrypt } from 'jsencrypt';
// 导入组件
import {
  oemQueryAgentList,
  oemAgentListQueryBusiness,
  dsfmerenterinfoPage,
  selectByPrimaryKey,
  getMerenterInfo,
  merApplyFor
} from '@/api/lncomingManagement/incomingListApi';
import ElImageViewer from 'element-ui/packages/image/src/image-viewer';
import Steps from '@/components/Steps/Steps.vue';
import { getRegionLabel } from 'ele-admin/packages/utils/regions';
import axios from 'axios';
import {
  certTypeList,
  mccOptions,
  optionsServiceList,
  qualificationTypeOptions,
  accountBankOptions,
  bankAccountTypeOptions,
  usageTypeOptions,
  accountTypeOptions,
  rules,
  list,
  idDocTypeOptions,
  wxSumbitForm,
  validateLogo,
  storeEntrancePicLogo,
  indoorPicLogo,
  idCardCopyLogo,
  idCardNationalLogo,
  qualificationsLogo,
  outDoorImagesLogo,
  inDoorImagesLogo,
  certImageLogo,
  certImageBackLogo,
  zfbSumbitForm,
  oemList,
  merchanApplyForStatusList
} from './constant/constant';
export default {
  name: 'agentIncomingList',
  components: {
    UserSearch,
    EquipmentEdit,
    UserEdit,
    UserImport,
    ElImageViewer,
    Steps,
    RegionsSelect,
    incomingDetails
  },
  data () {
    validateLogo;
    storeEntrancePicLogo,
      indoorPicLogo,
      idCardCopyLogo,
      idCardNationalLogo,
      qualificationsLogo;
    outDoorImagesLogo, inDoorImagesLogo, certImageLogo, certImageBackLogo;

    return {
      wxSumbitForm,
      certTypeList,
      mccOptions,
      optionsServiceList,
      qualificationTypeOptions,
      accountBankOptions,
      bankAccountTypeOptions,
      usageTypeOptions,
      accountTypeOptions,
      rules,
      list,
      idDocTypeOptions,
      zfbSumbitForm,

      windowHeight: document.documentElement.clientHeight,
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      visibleModal: false,
      dialogImageUrl: '',
      dialogVisible: false,
      disabled: false,
      // 是否弹框
      drawer: false,
      // 代理类型list
      typeList: [],
      //   驳回原因
      rejectReason: '',
      //   下属代理配置
      subordinateAgentList: [],
      //  商家进件id
      merchantIdList: [],
      //   加载中
      loading: false,
      merchanApplyForStatusList: [],
      omeId: '',
      //  当前进件列表的id
      id: '',

      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: 'left',
          sortable: true
        },
        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left',
          sortable: true
        },
        {
          prop: 'merchantName',
          //   prop: 'MerchantName',
          label: '商家名称',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          align: 'center',
          sortable: true
        },

        {
          prop: 'merType',
          label: '商户类型',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          align: 'center',
          sortable: true
        },

        {
          prop: 'businName',
          label: '商户名称',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          align: 'center',
          sortable: true
        },
        {
          prop: 'status',
          label: '进件状态',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'status',
          align: 'center',
          sortable: true
        },
        {
          prop: 'funcType',
          label: '进件类型',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'funcType',
          align: 'center',
          sortable: true
        },
        {
          prop: 'createDate',
          label: '申请时间',
          align: 'center',
          sortable: 'custom',
          showOverflowTooltip: true,
          minWidth: 150,
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue);
          }
        },

        {
          columnKey: 'action',
          label: '操作',
          width: 350,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true,
          fixed: 'right'
        }
      ],
      currentlistInformation: null,
      // 费率设置
      merchantHandlingCharge: '',
      // 微信存储的图片
      wxPictureArr: [],
      // 支付宝存储的图片
      zfbPictureArr: [],
      // 获取图片列表
      pictureList: [],
      // 获取图片文件列表
      fileList: [],
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      // 是否显示编辑弹窗
      showEdit: false,
      // 是否显示导入弹窗
      showImport: false,
      //是否显示划拨编辑弹窗
      showTransfer: false,
      showViewer: false, // 显示查看器
      //  查看详情
      viewDetailObject: null,
      //步骤标题
      stepsLabel: ['主体信息', '辅助类信息', '提交完成'],
      //   步骤描述
      stepsDesc: ['准备营业执照', '发布配置', '选择素材'],

      labelPosition: 'top',

      listLength: 0, //图片数量

      // 状态 1 为 微信 2 为支付宝 3为查看详情
      jjstatus: '',

      //  wx当前步骤 默认为第一步
      currentStepIndex: 1,
      // 支付宝 步骤
      zfbCurrentStepIndex: 1,
      // 其他银行
      otherBanks: false,

      //   ref 图片
      uploadFilesArr: [],
      //   签约二维码
      signUrl: '',
      // 进件流程状态
      incomingStatus: '',
      //   当前所在平台
      currentPlatform: '',
      isDisabled: true
    };
  },
  // 路由刷新
  activated () {
    this.init();

    this.merchanApplyForStatusList = merchanApplyForStatusList;
    if (
      this.$store.state.user.info.oemId == null &&
      this.$store.state.user.info.merchantId == null
    ) {
      console.log('总平台');
      this.currentPlatform = '总平台';
    } else if (
      this.$store.state.user.info.oemId !== null &&
      this.$store.state.user.info.merchantId == null
    ) {
      console.log('oem代理');
      this.currentPlatform = 'oem代理';
    } else {
      console.log('商家端');
      this.currentPlatform = '商家端';
    }
    console.log(this.$store.state.user.info.oemId);
    this.oemId = this.$store.state.user.info.oemId;
  },
  created () {
    this.initRules();
    // this.currentStepIndex = 1
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    },
    applyForType () {
      return function (applyType) {
        if (applyType == '1') {
          return '微信';
        } else if (applyType == '2') {
          return '支付宝';
        } else {
          return '全部';
        }
      };
    },

    merchanApplyForStatus () {
      return function (applyType) {
        console.log(applyType);
        if (applyType == '9') {
          return {
            status: '未处理',
            type: 'info'
          };
        } else if (applyType == '3') {
          return {
            status: '待审核',
            type: ''
          };
        } else if (applyType == 'X') {
          return {
            status: '审核失败',
            type: 'danger'
          };
        } else if (applyType == '0') {
          return {
            status: '审核通过',
            type: 'success'
          };
        } else if (applyType == '1') {
          return {
            status: '审核驳回',
            type: 'danger'
          };
        } else if (applyType == '5') {
          return {
            status: '待签约',
            type: ''
          };
        }
      };
    }
  },
  methods: {
    async qianyue (row) {
      // 签约成功 延迟30后才可以继续签约
      if (this.isDisabled) {
        console.log(row.merTrace, row);
        const res = await merSigningApplicationo({
          merTrace: row.merTrace,
          id: row.id,
          merchantId: row.merchantId
        });
        if (res.code == 2000) {
          this.$message.success(res.msg);
          this.reload();
          this.isDisabled = false;
        } else {
          this.$message.success(res.msg);
          this.reload();
        }
      } else {
        this.$message.error('签约太频繁请稍后在试');
      }

      setTimeout(() => {
        // 启用按钮
        this.isDisabled = true;
      }, 10000);
    },
    copySrc (link) {
      this.$copyText(link).then(
        (e) => {
          this.$message({
            message: '复制成功',
            type: 'success'
          });
        },
        (e) => {
          this.$message.error('复制失败');
        }
      );
    },
    // 下载pdf
    async electronicProtocolDownloadFn (row) {
      const res = await electronicProtocolDownloadApi({
        contractNo: row.contractNo
      });
      console.log(res);
      let URL = this.dataURLtoBlob(res.msg);
      var reader = new FileReader();
      reader.readAsDataURL(URL);
      reader.onload = function (e) {
        // 兼容IE
        if (window.navigator.msSaveOrOpenBlob) {
          var bstr = atob(e.target.result.split(',')[1]);
          var n = bstr.length;
          var u8arr = new Uint8Array(n);
          while (n--) {
            u8arr[n] = bstr.charCodeAt(n);
          }
          var blob = new Blob([u8arr]);
          window.navigator.msSaveOrOpenBlob(blob, '电子协议.pdf');
        } else {
          // 转换完成，创建一个a标签用于下载
          var a = document.createElement('a');
          a.download = '电子协议.pdf';
          a.href = e.target.result;
          a.setAttribute('id', 'export');
          //   document.getElementById("purchaseManage").append(a); // 修复firefox中无法触发click
          a.click();
        }
      };

      //   var base64Data = res.msg; // 这里替换为你的 Base64 数据

      //   var binaryData = atob(base64Data);
      //   var blob = new Blob([binaryData], { type: 'application/pdf' });

      //   var downloadLink = document.createElement('a');
      //   downloadLink.href = URL.createObjectURL(blob);
      //   downloadLink.download = 'converted.pdf';
      //   downloadLink.click();
    },
    dataURLtoBlob (dataurl) {
      var bstr = atob(dataurl);
      var n = bstr.length;
      var u8arr = new Uint8Array(n);
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
      }
      return new Blob([u8arr], { type: 'pdf' });
    },

    innerVisibleFn () {
      //   如果状态为3 显示重新进件
      if (this.incomingStatus == 3) {
        this.openWeInbound(1);
        this.currentStepIndex = 1;
      }
    },
    // 打开对话框
    openElDialog (url, status) {
      this.visibleModal = !this.visibleModal;
    },

    handleClose (done) {
      this.$confirm('是否要返回进件列表页面关闭？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then((_) => {
          done();
        })
        .catch((_) => { });
    },
    // 切换进件结算类型
    switchSettlementType (settlementType) {
      console.log(settlementType);
      this.zfbSumbitForm.defaultSettleType = settlementType;
      this.initRules();
      this.zfbSumbitForm.defaultSettleTarget = '';
    },
    initRules () {
      console.log(this.zfbSumbitForm.merchantType);
      this.$set(this.rules, 'certNo', [
        { required: true, message: '请填写商户证件编号', trigger: 'blur' },
        {
          pattern:
            this.zfbSumbitForm.merchantType !== '06'
              ? /^[A-Z0-9]{18}$/
              : /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
          message:
            this.zfbSumbitForm.merchantType !== '06'
              ? '营业执照上的注册号/统一社会信用代码格式不对'
              : '身份证输入不合法'
        }
      ]);

      this.$set(this.rules, 'defaultSettleTarget', [
        { required: true, message: '请填写商户证件编号', trigger: 'blur' },
        {
          pattern:
            this.zfbSumbitForm.defaultSettleType == 'bankCard'
              ? /^([1-9])(\d{15}|\d{16}|\d{17}|\d{18})$/
              : /^[a-zA-Z0-9][a-zA-Z0-9._]{4,18}[a-zA-Z0-9]$/,
          message:
            this.zfbSumbitForm.defaultSettleType == 'bankCard'
              ? '请输入银行卡号'
              : '请输入支付宝账号登录号'
        }
      ]);
    },
    // mcc
    handleChangeMcc (value) {
      if (this.zfbSumbitForm.mcc.length) {
        this.$refs.zfbSumbitForm.clearValidate('mcc');
      }
      console.log(value[1]);
    },
    inputFn (e) {
      this.wxSumbitForm.idCardName = e;
      console.log(e);
    },
    verifyChangesFn (e) {
      console.log(e, this.wxSumbitForm.qualificationType);
      if (this.wxSumbitForm.qualificationType) {
        this.$refs.wxSumbitForm.clearValidate('qualificationType');
      }
      if (this.wxSumbitForm.idDocType) {
        this.$refs.wxSumbitForm.clearValidate('idDocType');
      }
      if (this.wxSumbitForm.bankAccountType) {
        this.$refs.wxSumbitForm.clearValidate('bankAccountType');
      }
      if (this.wxSumbitForm.usageType) {
        this.$refs.wxSumbitForm.clearValidate('usageType');
      }
      if (this.wxSumbitForm.accountType) {
        this.$refs.wxSumbitForm.clearValidate('accountType');
      }
      if (this.wxSumbitForm.serviceList) {
        this.$refs.wxSumbitForm.clearValidate('serviceList');
      }
    },
    // 提交图片之前的一些限制

    beforeAvatarUpload (file) {
      // const isJPG = file.type === 'image/jpeg';
      console.log(file);
      const isJPG = file.raw.type;
      const isLt2M = file.raw.size / 1024 / 1024 < 2;

      const extension1 = file.raw.type === 'image/jpg';
      const extension2 = file.raw.type === 'image/jpeg';
      const extension3 = file.raw.type === 'image/png';
      const extension4 = file.raw.type === 'image/bmp';
      if (!extension1 && !extension2 && !extension3 && !extension4) {
        this.$message.error('请上传jpg 、png、jpeg 类型图片!');
      }
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    accountBankFn (item) {
      if (this.wxSumbitForm.accountBank) {
        this.$refs.wxSumbitForm.clearValidate('accountBank');
      }
      console.log(item);
      // console.log('http://' + window.location.host.split(':')[0]);
      if (item == '其他银行') {
        this.otherBanks = !this.otherBanks;
      } else {
        this.otherBanks = false;
      }
    },
    // 身份证有效时间
    IDCardDateRange (timeArr) {
      console.log(timeArr);
      //   开始时间
      this.wxSumbitForm.cardPeriodBegin = timeArr[0];
      //   结束时间
      this.wxSumbitForm.cardPeriodEnd = timeArr[1];
    },

    // 清除城市的校验
    regionsInput (value, nameCode) {
      console.log(value, '==============', nameCode);
      if (nameCode == 'licenseCode') {
        this.zfbSumbitForm.provinceCode = value[0];
        this.zfbSumbitForm.cityCode = value[1];
        this.zfbSumbitForm.districtCode = value[2];
      }
      if (nameCode == 'accountInstCode') {
        console.log(getRegionLabel(value));
        const regionLabel = getRegionLabel(value);
        // 开户行所在的省
        this.zfbSumbitForm.accountInstProvince = regionLabel[0];
        // 开户行所在的市
        this.zfbSumbitForm.accountInstCity = regionLabel[1];
      }
      if (this.wxSumbitForm.bizAddressCode.length) {
        this.$refs.wxSumbitForm.clearValidate('bizAddressCode');
      }
      if (this.wxSumbitForm.bankAddressCode.length) {
        this.$refs.wxSumbitForm.clearValidate('bankAddressCode');
      }
      if (this.zfbSumbitForm.districtCode.length) {
        this.$refs.zfbSumbitForm.clearValidate('districtCode');
      }
      if (this.zfbSumbitForm.licenseCode.length) {
        this.$refs.zfbSumbitForm.clearValidate('licenseCode');
      }
      if (this.zfbSumbitForm.accountInstCode.length) {
        this.$refs.zfbSumbitForm.clearValidate('accountInstCode');
      }
    },
    // 勾选 有效期 那么periodEnd变为长期
    switchCheckbox (checked) {
      this.wxSumbitForm.checked = checked;
      // 如果勾选 那么营业结束时间变为长期
      if (checked) {
        this.wxSumbitForm.periodEnd = '';
      } else {
        this.wxSumbitForm.periodEnd = '';
      }
    },
    // 营业执照有效时间
    businessLicense (timeArr, periodName) {
      console.log(timeArr, periodName);
      //   开始时间
      if (periodName == 'periodBegin') {
        this.wxSumbitForm.periodBegin = timeArr;
      } else {
        //   结束时间
        this.wxSumbitForm.periodEnd = timeArr;
      }
    },
    //  图片上传个数超过限制
    exceedFn () {
      this.$message({
        message: '图片上传已达到上限,请删除后再上传',
        type: 'warning'
      });
    },
    // 这里对图片上传以后当图片数量大于0则去除校验提示

    handleFileChange (file, fileList, name) {
      if (file.status !== 'ready') return;
      const isPass = this.beforeAvatarUpload(file);
      console.log(isPass);
      if (!isPass) {
        this.handleRemove(file, name);
        return;
      }

      //图片上传后
      console.log(file);
      this.listLength = fileList.length;
      if (name == 'licenseCopy') {
        this.wxSumbitForm.licenseCopy = file.name;
      } else if (name == 'qualifications') {
        this.wxSumbitForm.qualifications = file.name;
      } else if (name == 'storeEntrancePic') {
        this.wxSumbitForm.storeEntrancePic = file.name;
      } else if (name == 'indoorPic') {
        this.wxSumbitForm.indoorPic = file.name;
      } else if (name == 'idCardCopy') {
        this.wxSumbitForm.idCardCopy = file.name;
      } else if (name == 'idCardNational') {
        this.wxSumbitForm.idCardNational = file.name;
      } else if (name == 'inDoorImages') {
        this.zfbSumbitForm.inDoorImages = file.name;
      } else if (name == 'certImage') {
        this.zfbSumbitForm.certImage = file.name;
      } else if (name == 'certImageBack') {
        this.zfbSumbitForm.certImageBack = file.name;
      } else if (name == 'outDoorImages') {
        this.zfbSumbitForm.outDoorImages = file.name;
      }
      this.$nextTick(() => {
        let uploadFiles;
        if (name == 'idCardCopy') {
          uploadFiles = this.$refs.pictureUploadIdCardCopy.uploadFiles;
          this.uploadFilesArr.push(uploadFiles[0]);
        }
        if (name == 'idCardNational') {
          uploadFiles = this.$refs.pictureUploadIdCardNational.uploadFiles;
          this.uploadFilesArr.push(uploadFiles[0]);
        }
      });
      fileList.forEach((item) => {
        item.imgType = name;
      });
      let files = fileList[fileList.length - 1];
      this.fileList.push(files);
      console.log(file, fileList, this.fileList, name);
      if (this.listLength > 0) {
        // 这里还需要判断一下图片的类型 只有有当前的类型才去除验证
        const fileObject = this.fileList.find((item, index) => {
          return item.imgType == name;
        });
        if (this.jjstatus == '1') {
          this.$refs.wxSumbitForm.clearValidate(fileObject.imgType); //当图片数量大于0则去除校验提示
        } else {
          this.$refs.zfbSumbitForm.clearValidate(fileObject.imgType); //当图片数量大于0则去除校验提示
        }
      }
      if (this.jjstatus == '1') {
        this.wxUploadBj();
      } else {
        this.zfbUploadBj();
      }
    },
    handleRemove (file, removeName) {
      let uploadFiles;
      // 进行判断 对不同的数据进行不同的图片的删除
      if (removeName == 'licenseCopy') {
        uploadFiles = this.$refs.pictureUploadLicenseCopy.uploadFiles;
      } else if (removeName == 'storeEntrancePic') {
        uploadFiles = this.$refs.pictureUploadStoreEntrancePic.uploadFiles;
      } else if (removeName == 'indoorPic') {
        uploadFiles = this.$refs.pictureUploadIndoorPic.uploadFiles;
      } else if (removeName == 'qualifications') {
        uploadFiles = this.$refs.pictureUploadQualifications.uploadFiles;
      } else if (removeName == 'pictureUploadIdCardCopy') {
        uploadFiles = this.$refs.pictureUpload.uploadFiles;
      } else if (removeName == 'idCardCopy') {
        uploadFiles = this.$refs.pictureUploadIdCardCopy.uploadFiles;
      } else if (removeName == 'idCardNational') {
        uploadFiles = this.$refs.pictureUploadIdCardNational.uploadFiles;
      } else if (removeName == 'outDoorImages') {
        uploadFiles = this.$refs.pictureUploadOutDoorImages.uploadFiles;
      } else if (removeName == 'inDoorImages') {
        uploadFiles = this.$refs.pictureUploadInDoorImages.uploadFiles;
      } else if (removeName == 'certImage') {
        uploadFiles = this.$refs.pictureUploadIdCertImage.uploadFiles;
      } else if (removeName == 'certImageBack') {
        uploadFiles = this.$refs.pictureUploadIdCertImage.uploadFiles;
      }
      console.log(file, uploadFiles, this.uploadFilesArr);

      // 获取到该图片的uid 去  this.fileList 去匹配到uid 找到然后去删除掉
      if (this.fileList.length) {
        const uidIndex = this.fileList.findIndex((item, index) => {
          return item.uid == file.uid;
        });
        console.log(uidIndex);
        if (uidIndex !== -1) {
          this.fileList.splice(uidIndex, 1);
        }
      }

      this.uploadFilesArr.forEach((item, index) => {
        if (item.url == file.url) {
          this.uploadFilesArr.splice(index, 1);
        }
      });
      for (let i = 0; i < uploadFiles.length; i++) {
        if (uploadFiles[i]['url'] == file.url) {
          uploadFiles.splice(i, 1);
        }
      }

      console.log(this.uploadFiles);
      console.log(this.uploadFilesArr);
      // 需要把对应上传的图片和 和id 需要删除

      if (this.jjstatus == '1') {
        const picIndex = this.wxPictureArr.findIndex((item) => {
          return item.uid == file.raw.uid;
        });

        this.wxPictureArr.splice(picIndex, 1);
      } else {
        const picIndex = this.zfbPictureArr.findIndex((item) => {
          return item.uid == file.raw.uid;
        });

        this.zfbPictureArr.splice(picIndex, 1);
      }

      if (removeName == 'licenseCopy') {
        const mediaIdIndex = this.wxSumbitForm.licenseCopyMediaId.findIndex(
          (item) => {
            return item.uid == file.uid;
          }
        );
        this.wxSumbitForm.licenseCopyMediaId.splice(mediaIdIndex, 1);
      } else if (removeName == 'storeEntrancePic') {
        const mediaIdIndex =
          this.wxSumbitForm.storeEntrancePicMediaId.findIndex((item) => {
            return item.uid == file.uid;
          });
        this.wxSumbitForm.storeEntrancePicMediaId.splice(mediaIdIndex, 1);
      } else if (removeName == 'qualifications') {
        const mediaIdIndex =
          this.wxSumbitForm.qualificationsMediaId.findIndex((item) => {
            return item.uid == file.uid;
          });
        this.wxSumbitForm.qualificationsMediaId.splice(mediaIdIndex, 1);
      } else if (removeName == 'idCardCopy') {
        const mediaIdIndex = this.wxSumbitForm.idCardCopyMediaId.findIndex(
          (item) => {
            return item.uid == file.uid;
          }
        );
        this.wxSumbitForm.idCardCopyMediaId.splice(mediaIdIndex, 1);
      } else if (removeName == 'indoorPic') {
        const mediaIdIndex = this.wxSumbitForm.indoorPicMediaId.findIndex(
          (item) => {
            return item.uid == file.uid;
          }
        );
        this.wxSumbitForm.indoorPicMediaId.splice(mediaIdIndex, 1);
      } else if (removeName == 'idCardNational') {
        const mediaIdIndex =
          this.wxSumbitForm.idCardNationalMediaId.findIndex((item) => {
            return item.uid == file.uid;
          });
        this.wxSumbitForm.idCardNationalMediaId.splice(mediaIdIndex, 1);
      } else if (removeName == 'outDoorImages') {
        const mediaIdIndex = this.zfbSumbitForm.outDoorImagesOssKey.findIndex(
          (item) => {
            return item.uid == file.uid;
          }
        );
        this.zfbSumbitForm.outDoorImagesOssKey.splice(mediaIdIndex, 1);
      } else if (removeName == 'inDoorImages') {
        const mediaIdIndex = this.zfbSumbitForm.inDoorImagesOssKey.findIndex(
          (item) => {
            return item.uid == file.uid;
          }
        );
        this.zfbSumbitForm.inDoorImagesOssKey.splice(mediaIdIndex, 1);
      } else if (removeName == 'certImage') {
        const mediaIdIndex = this.zfbSumbitForm.certImageOssKey.findIndex(
          (item) => {
            return item.uid == file.uid;
          }
        );
        this.zfbSumbitForm.certImageOssKey.splice(mediaIdIndex, 1);
      } else if (removeName == 'certImageBack') {
        const mediaIdIndex = this.zfbSumbitForm.certImageBackOssKey.findIndex(
          (item) => {
            return item.uid == file.uid;
          }
        );
        this.zfbSumbitForm.certImageBackOssKey.splice(mediaIdIndex, 1);
      }

      if (this.jjstatus == '1') {
        this.wxSumbitFilter();
      } else {
        this.zfbSumbitFilter();
      }
    },

    // 微信下属代理
    async getAgentParentIdList (ParentId, agentName) {
      console.log(ParentId, agentName);
      if (this.wxSumbitForm.subordinateAgent) {
        this.$refs.wxSumbitForm.clearValidate('subordinateAgent');
      }

      //   拿到ParentId 获取到商家信息
      const res = await oemAgentListQueryBusiness({
        limit: 10,
        oemId: ParentId,
        page: 1
      });
      console.log(res.data);
      this.wxSumbitForm.merchantId = '';
      if (res.data.list.length && res.code == 2000) {
        const merchantData = res.data.list.map((item, i) => {
          return {
            label: item.merchantName,
            value: item.id
          };
        });

        this.merchantIdList = merchantData;
      }
    },
    async wxUploadBj () {
      if (this.fileList.length < 1) {
        console.log('请选择文件后提交');
        this.$message.error('请选择文件后提交');
        return;
      }

      this.disabled = true;
      this.data = await userOssSignature();
      console.log(this.fileList[this.fileList.length - 1]);

      let file = this.fileList[this.fileList.length - 1].raw;
      let imgType = this.fileList[this.fileList.length - 1].imgType;
      let filename = file.name;
      let markIndex = filename.lastIndexOf('.');
      let suffix = filename.substring(markIndex);
      let date = new Date().getTime();
      // 构建请求参数
      let param = new FormData();
      param.append('key', this.data.dir + imgType + '/' + date + suffix);
      param.append('policy', this.data.policy);
      param.append('OSSAccessKeyId', this.data.accessId);
      param.append('success_action_status', '200');
      // param.append("callback",  this.data.callback)     //回调（not)
      param.append('signature', this.data.signature);
      param.append('file', file, file.name);
      param.append('success_action_status', '200');
      let config = {
        headers: {
          'Access-Control-Allow-Origin': '*',
          'x-oss-callback-Authorization': getToken()
        }
      };
      console.log('suffix', suffix);

      let res = await axios.post(this.data.host, param, config);
      let url;
      if (res.status == 200) {
        url = this.data.host + '/' + imgType + '/' + date + suffix;

        console.log('上传图片成功=======', res);
        console.log('this.data.host', url);

        this.wxPictureArr.push({ picUrls: url, uid: file.uid });
      } else {
        this.$message.error('上传失败');
      }

      const result = await wxGetUploadMediaId([url]);

      // console.log(result);

      // 当个MediaId 是字符串 多个是数组  营业执照和正反面的身份证是字符串格式其他的都是数组格式
      if (result.data.code == 200) {
        if (imgType == 'licenseCopy') {
          // 营业执照照片
          this.wxSumbitForm.licenseCopyMediaId = [
            { id: result.data.data.mediaId, uid: file.uid }
          ];
          console.log(this.wxSumbitForm.licenseCopyMediaId);
        } else if (imgType == 'storeEntrancePic') {
          // 门头照片
          this.wxSumbitForm.storeEntrancePicMediaId.push({
            id: result.data.data.mediaId,
            uid: file.uid
          });
          console.log(this.wxSumbitForm.storeEntrancePic);
        } else if (imgType == 'indoorPic') {
          // 办公环境
          this.wxSumbitForm.indoorPicMediaId.push({
            id: result.data.data.mediaId,
            uid: file.uid
          });
          console.log(this.wxSumbitForm.indoorPicMediaId);
        } else if (imgType == 'qualifications') {
          // 特殊资历
          this.wxSumbitForm.qualificationsMediaId.push({
            id: result.data.data.mediaId,
            uid: file.uid
          });
          console.log(this.wxSumbitForm.qualificationsMediaId);
        } else if (imgType == 'idCardCopy') {
          // 正面身份证头像
          this.wxSumbitForm.idCardCopyMediaId = [
            { id: result.data.data.mediaId, uid: file.uid }
          ];
          console.log(this.wxSumbitForm.idCardCopyMediaId);
        } else if (imgType == 'idCardNational') {
          // 反面身份证头像
          this.wxSumbitForm.idCardNationalMediaId = [
            { id: result.data.data.mediaId, uid: file.uid }
          ];
          console.log(this.wxSumbitForm.idCardNationalMediaId);
        }

        this.disabled = false;
      }
    },
    async zfbUploadBj () {
      if (this.fileList.length < 1) {
        console.log('请选择文件后提交');
        this.$message.error('请选择文件后提交');
        return;
      }
      this.data = await userOssSignature();

      let file = this.fileList[this.fileList.length - 1].raw;
      let imgType = this.fileList[this.fileList.length - 1].imgType;
      let filename = file.name;
      let markIndex = filename.lastIndexOf('.');
      let suffix = filename.substring(markIndex);
      let date = new Date().getTime();
      // 构建请求参数
      let param = new FormData();
      param.append('key', this.data.dir + imgType + '/' + date + suffix);
      param.append('policy', this.data.policy);
      param.append('OSSAccessKeyId', this.data.accessId);
      param.append('success_action_status', '200');
      // param.append("callback",  this.data.callback)     //回调（not)
      param.append('signature', this.data.signature);
      param.append('file', file, file.name);
      param.append('success_action_status', '200');
      let config = {
        headers: {
          'Access-Control-Allow-Origin': '*',
          'x-oss-callback-Authorization': getToken()
        }
      };
      console.log('suffix', suffix);

      let res = await axios.post(this.data.host, param, config);
      let url;
      if (res.status == 200) {
        url = this.data.host + '/' + imgType + '/' + date + suffix;

        console.log('上传图片成功=======', res);
        console.log('this.data.host', url);

        this.zfbPictureArr.push({ picUrls: url, uid: file.uid });
      } else {
        this.$message.error('上传失败');
      }
      //  获取到id
      const result = await zfbGetUploadMediaId([url]);

      console.log(result);

      // 当个MediaId 是字符串 多个是数组  营业执照和正反面的身份证是字符串格式其他的都是数组格式
      if (result.data.code == 200) {
        if (imgType == 'licenseCopy') {
          // 营业执照照片
          this.zfbSumbitForm.licenseCopyMediaId = result.data.data.imageId;
          console.log(this.zfbSumbitForm.licenseCopyMediaId);
        } else if (imgType == 'outDoorImages') {
          // 门头照片
          this.zfbSumbitForm.outDoorImagesOssKey.push({
            id: result.data.data.mediaId,
            uid: file.uid
          });
          // console.log(this.zfbSumbitForm.storeEntrancePic)
        } else if (imgType == 'inDoorImages') {
          // 办公环境
          this.zfbSumbitForm.inDoorImagesOssKey.push({
            id: result.data.data.mediaId,
            uid: file.uid
          });
        } else if (imgType == 'certImage') {
          // 正面身份证头像
          this.zfbSumbitForm.certImageOssKey = [
            { id: result.data.data.mediaId, uid: file.uid }
          ];
        } else if (imgType == 'certImageBack') {
          // 反面身份证头像
          this.zfbSumbitForm.certImageBackOssKey = [
            { id: result.data.data.mediaId, uid: file.uid }
          ];
        }
      }
    },
    wxSumbitFilter () {
      console.log(this.pictureList);
      this.pictureList = [];
      //  对图片进行分类

      this.wxPictureArr.forEach((item) => {
        this.pictureList.push(item.picUrls);
      });

      // 获取到不同的图片地址然后放到from表单中
      // 营业执照照片
      let licenseCopy = this.pictureList.filter((url) =>
        url.includes('licenseCopy')
      );

      this.wxSumbitForm.licenseCopy = licenseCopy.join(',');
      // 线下场所门头照片
      let storeEntrancePic = this.pictureList.filter((url) =>
        url.includes('storeEntrancePic')
      );
      this.wxSumbitForm.storeEntrancePic = storeEntrancePic.join(',');
      // 办公环境
      let indoorPic = this.pictureList.filter((url) =>
        url.includes('indoorPic')
      );
      this.wxSumbitForm.indoorPic = indoorPic.join(',');
      // 特殊资质图片
      let qualifications = this.pictureList.filter((url) =>
        url.includes('qualifications')
      );
      this.wxSumbitForm.qualifications = qualifications.join(',');
      // 身份证正面头像
      let idCardCopy = this.pictureList.filter((url) =>
        url.includes('idCardCopy')
      );
      this.wxSumbitForm.idCardCopy = idCardCopy.join(',');
      // 身份证反面头像
      let idCardNational = this.pictureList.filter((url) =>
        url.includes('idCardNational')
      );
      this.wxSumbitForm.idCardNational = idCardNational.join(',');
      console.log(this.wxSumbitForm);
    },
    zfbSumbitFilter () {
      //  对图片进行分类
      this.pictureList = [];
      this.zfbPictureArr.forEach((item) => {
        this.pictureList.push(item.picUrls);
      });

      // 获取到不同的图片地址然后放到from表单中
      console.log(this.pictureList);
      let outDoorImagesPic = this.pictureList.filter((url) =>
        url.includes('outDoorImages')
      );
      this.zfbSumbitForm.outDoorImages = outDoorImagesPic.join(',');
      // 办公环境
      let inDoorImagesPic = this.pictureList.filter((url) =>
        url.includes('inDoorImages')
      );
      this.zfbSumbitForm.inDoorImages = inDoorImagesPic.join(',');

      // 身份证正面头像
      let certImagePic = this.pictureList.filter(
        (url) => url.includes('certImage') && !url.includes('certImageBack')
      );
      console.log(certImagePic);
      this.zfbSumbitForm.certImage = certImagePic.join(',');
      // 身份证反面头像
      let certImageBackPic = this.pictureList.filter((url) =>
        url.includes('certImageBack')
      );
      this.zfbSumbitForm.certImageBack = certImageBackPic.join(',');

      console.log(this.wxSumbitForm);
    },
    async wxSumbit () {
      this.wxSumbitFilter();
      // 把submitFrom 转化为  {merchantsapplyfor:{}，businesslicense：{}}
      console.log(this.wxSumbitForm);
      let params = {
        merchantsapplyfor: {
          merchantId: this.wxSumbitForm.merchantId,
          subordinateAgent: this.wxSumbitForm.subordinateAgent,
          mobilePhone: this.wxSumbitForm.mobilePhone,
          contactEmail: this.wxSumbitForm.contactEmail,
          subjectType: this.wxSumbitForm.subjectType,
          idDocType: this.wxSumbitForm.idDocType,
          idCardCopy: this.wxSumbitForm.idCardCopy,
          // 身份证正面
          idCardCopyMediaId: this.wxSumbitForm.idCardCopyMediaId
            .map((item) => item.id)
            .join(),
          idCardNational: this.wxSumbitForm.idCardNational,
          // 身份证反面
          idCardNationalMediaId: this.wxSumbitForm.idCardNationalMediaId
            .map((item) => item.id)
            .join(),

          idCardName: this.wxSumbitForm.idCardName,
          idCardNumber: this.wxSumbitForm.idCardNumber,
          idCardAddress: this.wxSumbitForm.idCardAddress,
          cardPeriodBegin: this.wxSumbitForm.cardPeriodBegin,
          cardPeriodEnd: this.wxSumbitForm.cardPeriodEnd
        },
        businesslicense: {
          licenseCopy: this.wxSumbitForm.licenseCopy,
          // 营业执照 MediaId
          licenseCopyMediaId: this.wxSumbitForm.licenseCopyMediaId
            .map((item) => item.id)
            .join(),
          licenseNumber: this.wxSumbitForm.licenseNumber,
          merchantName: this.wxSumbitForm.merchantName,
          legalPerson: this.wxSumbitForm.legalPerson,
          licenseAddress: this.wxSumbitForm.licenseAddress,
          periodBegin: this.wxSumbitForm.periodBegin,
          periodEnd: this.wxSumbitForm.periodEnd
            ? this.wxSumbitForm.periodEnd
            : '长期'
        },
        bankaccount: {
          bankAccountType: this.wxSumbitForm.bankAccountType,
          accountName: this.wxSumbitForm.accountName,
          accountBank: this.wxSumbitForm.accountBank,
          bankBranchId: this.wxSumbitForm.bankBranchId,
          bankName: this.wxSumbitForm.bankName,
          accountNumber: this.wxSumbitForm.accountNumber,
          bankAddressCode: this.bankAddressCode()
        },
        businessinfo: {
          merchantShortname: this.wxSumbitForm.merchantShortname,
          servicePhone: this.wxSumbitForm.servicePhone,

          bizStoreName: this.wxSumbitForm.bizStoreName,
          bizAddressCode: this.bizAddressCode(),
          bizStoreAddress: this.wxSumbitForm.bizStoreAddress,
          storeEntrancePic: this.wxSumbitForm.storeEntrancePic,
          // 门头照片 MediaId
          storeEntrancePicMediaId:
            this.wxSumbitForm.storeEntrancePicMediaId.map((item) => item.id),
          indoorPic: this.wxSumbitForm.indoorPic,
          // 线下场所内部照片
          indoorPicMediaId: this.wxSumbitForm.indoorPicMediaId.map(
            (item) => item.id
          )
        },
        settlement: {
          settlementId: this.wxSumbitForm.settlementId,
          qualificationType: this.wxSumbitForm.qualificationType,
          qualifications: this.wxSumbitForm.qualifications,
          // 特殊资质 MediaId
          qualificationsMediaId: this.wxSumbitForm.qualificationsMediaId.map(
            (item) => item.id
          ),
          activitiesRate: this.wxSumbitForm.activitiesRate
        }
      };

      console.log(params);

      try {
        this.loading = true;
        const res = await wxSumbitMerchantApplyFor(params);
        console.log(res);
        if (res.data.code == 2000) {
          this.$message({
            message: res.data.msg,
            type: 'success'
          });

          this.loading = false;
        }
        if (res.data.code == 5000) {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
      } catch (error) {
        this.$message.error(error);
      }
      this.pictureList = [];
    },
    async zfbSumbit () {
      this.zfbSumbitFilter();
      let params = {
        alipaymerchant: {
          // mcc
          mcc: this.zfbSumbitForm.mcc[1],
          // 商户类型
          merchantType: this.zfbSumbitForm.merchantType,
          // 商户名称
          name: this.zfbSumbitForm.name,
          // 商户别名
          aliasName: this.zfbSumbitForm.aliasName,

          // 商户证件编号
          certNo: this.zfbSumbitForm.certNo,
          // 商户证件类型
          certType: this.zfbSumbitForm.certType,
          // 法人名称
          legalName: this.zfbSumbitForm.legalName,
          // 法人身份证号
          legalCertNo: this.zfbSumbitForm.legalCertNo,
          // 联系人姓名
          contactName: this.zfbSumbitForm.contactName,
          // 联系人电话
          contactMobile: this.zfbSumbitForm.contactMobile,
          // 商户使用服务
          service: this.zfbSumbitForm.serviceList.join(','),
          // 商户使用服务  String[]
          serviceList: this.zfbSumbitForm.serviceList,
          // 结算支付宝账号
          alipayLogonId: this.zfbSumbitForm.alipayLogonId,
          // 营业执照名称
          certName: this.zfbSumbitForm.certName,
          // 签约支付宝账户
          bindingAlipayLogonId: this.zfbSumbitForm.bindingAlipayLogonId,
          // 默认结算类型
          defaultSettleType: this.zfbSumbitForm.defaultSettleType,
          // 默认结算目标
          defaultSettleTarget: this.zfbSumbitForm.defaultSettleTarget,
          // 办公环境
          inDoorImages: this.zfbSumbitForm.inDoorImages,
          // 办公环境OssKey
          inDoorImagesOssKey: this.zfbSumbitForm.inDoorImagesOssKey.map(
            (item) => item.id
          ),
          // 商户证件图片url
          certImage: this.zfbSumbitForm.certImage,
          // 商户证件图片urlOssKey
          certImageOssKey: this.zfbSumbitForm.certImageOssKey.map(
            (item) => item.id
          ),

          // 证件反面图片
          certImageBack: this.zfbSumbitForm.certImageBack,
          // 证件反面图片OssKey
          certImageBackOssKey: this.zfbSumbitForm.certImageBackOssKey.map(
            (item) => item.id
          ),
          // 城市编码
          cityCode: this.zfbSumbitForm.cityCode,
          // 区县编码
          districtCode: this.zfbSumbitForm.districtCode,
          // 营业执照地址
          address: this.zfbSumbitForm.address,
          // 省份编码
          provinceCode: this.zfbSumbitForm.provinceCode,
          // 门头照
          outDoorImages: this.zfbSumbitForm.outDoorImages,
          // 门头照OssKey
          outDoorImagesOssKey: this.zfbSumbitForm.outDoorImagesOssKey.map(
            (item) => item.id
          )
        },
        settlecardinfo: {
          // 卡户名
          accountHolderName: this.zfbSumbitForm.accountHolderName,
          // 银行卡号
          accountNo: this.zfbSumbitForm.accountNo,
          // 开户行所在地-省
          accountInstProvince: this.zfbSumbitForm.accountInstProvince,
          // 开户行所在地-市
          accountInstCity: this.zfbSumbitForm.accountInstCity,
          // 开户支行名
          accountBranchName: this.zfbSumbitForm.accountBranchName,
          // 账号使用类型
          usageType: this.zfbSumbitForm.usageType,
          // 银行卡类型
          accountType: this.zfbSumbitForm.accountType,
          // 银行名称
          accountInstName: this.zfbSumbitForm.accountInstName,
          // 开户行简称缩写
          accountInstId: this.zfbSumbitForm.accountInstId
        }
      };

      console.log(params);
      try {
        const res = await zfbMerchantCreate(params);
        console.log(res);
        if (res.data.code == 2000) {
          this.$message({
            message: res.data.msg,
            type: 'success'
          });
        }
        if (res.data.code == 5000) {
          this.$message.error(res.data.msg);
        }
      } catch (error) {
        this.$message.error(error);
      }
      this.pictureList = [];
    },
    // 微信商家id
    getMerchantIdList (merchantId, agentName) {
      if (this.wxSumbitForm.merchantId) {
        this.$refs.wxSumbitForm.clearValidate('merchantId');
      }
      console.log(merchantId, agentName);
    },
    //是否要关闭抽屉
    cancelForm () {
      console.log('1221313');
      this.drawer = false;
    },
    // 表单重置
    resetForm (formName) {
      console.log(formName);
      this.$refs[formName].resetFields();
    },
    // 对正则进行校验 ok了进行下一步
    submitForm (formName) {
      this.loading = true;
      this.$refs[formName].validate((valid) => {
        if (this.jjstatus == '1') {
          if (valid) {
            //如果成功那么进入下一步
            if (this.currentStepIndex == 1) {
              this.currentStepIndex = 2;
              console.log(this.uploadFilesArr);
              if (this.uploadFilesArr.length) {
                this.$nextTick(() => {
                  this.uploadFilesArr.forEach((item, index) => {
                    console.log(item);
                    item.url = URL.createObjectURL(item.raw);

                    if (item.imgType == 'idCardCopy') {
                      this.$refs.pictureUploadIdCardCopy.uploadFiles = [item];
                    }
                    if (item.imgType == 'idCardNational') {
                      this.$refs.pictureUploadIdCardNational.uploadFiles = [
                        item
                      ];
                    }
                  });
                });
              }

              return;
            } else if (this.currentStepIndex == 2) {
              this.wxSumbit();
            }
          } else {
            this.$message.error('参数填充有误,请填写完整参数在提交');

            return false;
          }
        } else {
          if (valid) {
            //如果成功那么进入下一步
            if (this.zfbCurrentStepIndex == 1) {
              this.zfbCurrentStepIndex = 2;
              cosnole.log(this.uploadFilesArr);

              return;
            } else if (this.zfbCurrentStepIndex == 2) {
              // 这里进行合并提交
              this.pictureList = [];

              this.zfbSumbit();
              // this.wxuploadBj();
            }
          } else {
            this.$message.error('参数填充有误,请填写完整参数在提交');
            return false;
          }
        }
      });
    },

    // 点击按钮预览图片
    onPreview () {
      this.showViewer = true;
    },
    // 关闭查看器
    closeViewer () {
      this.showViewer = false;
    },

    // 查询代理类型
    init () {
      pageAgencyType({
        deleted: 0,
        limit: 10,
        page: 1,
        types: 1
      })
        .then((data) => {
          this.typeList = data.list;
          console.log('data==', data);
        })
        .catch((e) => {
          this.$message.error(e.message);
        });
    },

    // 返回上一页
    previousPage () {
      if (this.jjstatus == '1') {
        this.currentStepIndex = this.currentStepIndex - 1;
        if (this.currentStepIndex == 1) {
          this.currentStepIndex = 1;
        }
      } else {
        this.zfbCurrentStepIndex = this.zfbCurrentStepIndex - 1;
        if (this.zfbCurrentStepIndex == 1) {
          this.zfbCurrentStepIndex = 1;
        }
      }
    },
    // 查看详情页面
    async viewDetail (id, status) {
      console.log(id);
      const res = await getMerenterInfo({ id: id });
      console.log(res);
      if (res.code == 2000) {
        this.drawer = true;
        this.viewDetailObject = res.data;
      }
    },

    inputChangeWx (e, value) { },
    async visibleModalFn (value, currentlistInformation) {
      console.log(value);
      if (typeof value == 'number') {
        if (value > 100) {
          this.$message({
            message: '输入的费率大于100请重新输入',
            type: 'warning'
          });
          this.merchantHandlingCharge = 100;
          return;
        }
      }
      if (value) {
        console.log(value);
        console.log(this.$store.state.user.info.merchantId)
        this.visibleModal = !this.visibleModal;
        console.log(currentlistInformation.id, this.merchantHandlingCharge);
        const res = await merApplyFor({
          id: currentlistInformation.id,
          merchantHandlingCharge: this.merchantHandlingCharge,
          merchantId: 494

        });
        console.log(res);
        if (res.code == 2000) {
          this.$message.success(res.msg);

          this.reload();
        } else {
          this.$message.error(res.msg);
        }
      } else {
        this.$message({
          message: '请输入商家进件费率',
          type: 'warning'
        });
      }
    },
    //
    async statusFn (row) {
      this.currentlistInformation = row;
      this.incomingStatus = row.status;
      console.log(this.currentlistInformation);
      // 先调用弹框输入商家进件费率
      this.visibleModal = !this.visibleModal;
    },
    // 打开微信进件
    async openWeInbound (index) {
      this.drawer = true;
      // oem查询代理列表 接口调用
      console.log(this.$store.state.user.info.oemId);

      const res = await oemQueryAgentList({
        limit: 10,
        oemType: 2,
        page: 1,
        parentId: this.$store.state.user.info.oemId
      });
      // 下属代理的数据
      console.log(res);

      if (res.code == 2000 && res.data.list.length) {
        const agentList = res.data.list.map((item) => {
          return {
            label: item.oemCode,
            value: item.id
          };
        });
        this.subordinateAgentList = agentList;
        console.log(this.subordinateAgentList);
      }

      this.jjstatus = index;
    },
    // 获取第在的code编码
    bankAddressCode () {
      if (this.wxSumbitForm.bankAddressCode) {
        const res =
          this.wxSumbitForm.bankAddressCode?.[
          this.wxSumbitForm.bankAddressCode.length - 1
          ];
        return res;
      }
    },

    bizAddressCode () {
      if (this.wxSumbitForm.bankAddressCode) {
        const res =
          this.wxSumbitForm.bizAddressCode?.[
          this.wxSumbitForm.bankAddressCode.length - 1
          ];
        return res;
      }
    },
    /* 表格数据源 */
    async datasource ({ page, limit, where, order }) {
      //   console.log(where, order);
      console.log(this.mccOptions);

      const res = await dsfmerenterinfoPage({
        page,
        limit,
        oemId: this.$store.state.user.info.oemId,
        ...where
      });

      res.list.forEach((a) => {
        this.mccOptions.forEach((b) => {
          if (a.merType == b.value) {
            a.merType = b.label;
          }
        });
      });
      console.log(res);
      return res;

      // return oemList;
    },

    /* 刷新表格 */
    reload (where) {
      console.log('where', where);
      this.$refs.table.reload({ page: 1, limit: 10, where: where });
    },
    modifyRate (id) {
      this.current = null;
      console.log(id);
      this.id = id;
      this.showEdit = true;
    },
    /* 打开划拨编辑弹窗 */
    openTransfer (row) {
      this.current = row;
      this.showTransfer = true;
    },
    /* 打开导入弹窗 */
    openImport () {
      this.showImport = true;
    },
    /* 删除 */
    remove (row) {
      const loading = this.$loading({ lock: true });
      removeUsers({ ids: [row.id] })
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
    },
    /*重置密码*/
    resets (row) {
      const loading = this.$loading({ lock: true });
      console.log('row', row);
      resetPassword({ id: row.id })
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
    },
    /* 批量删除 */
    removeBatch () {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      this.$confirm('确定要删除选中的代理吗?', '提示', {
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({ lock: true });
          removeUsers({ ids: this.selection.map((d) => d.id) })
            .then((msg) => {
              loading.close();
              this.$message.success(msg);
              this.reload();
            })
            .catch((e) => {
              loading.close();
              this.$message.error(e.message);
            });
        })
        .catch(() => { });
    },
    /* 更改状态 */
    editStatus (row) {
      const loading = this.$loading({ lock: true });
      updateUserStatus(row.id, row.status)
        .then((msg) => {
          console.log('msg=======', msg);
          loading.close();
          this.$message.success(
            row.status == 1 ? '启用成功！' : '冻结成功！'
          );
        })
        .catch((e) => {
          loading.close();
          row.status = !row.status ? 1 : 0;
          this.$message.error(e);
        });
    },

    // 切换 0 为 个人 1 为企业
    switchType (index) {
      if (this.jjstatus == '1') {
        this.wxSumbitForm.subjectType = index;
        if (index == 'SUBJECT_TYPE_INDIVIDUAL') {
          //   个人 719
          this.wxSumbitForm.settlementId = '746';
        } else {
          this.wxSumbitForm.settlementId = '711';
        }
      } else {
        this.zfbSumbitForm.merchantType = index;
        // 01：企业；cert_type填写201（营业执照）；cert_no填写营业执照号；
        // 06：个人商户：cert_type填写100（个人身份证）；cert_no填写个人身份证号码；
        // 07：个体工商户：cert_type填写201（营业执照）；cert_no填写营业执照编号；

        if (index == '01') {
          this.zfbSumbitForm.certType = this.certTypeList.businessLicense;
        } else if ('06') {
          this.zfbSumbitForm.certType = this.certTypeList.personalIDCard;
        } else if ('07') {
          this.zfbSumbitForm.certType = this.certTypeList.businessLicense;
        }
      }
      this.initRules();
    }
  }
};
</script>

<style lang="less" scoped>
.SigningReminder {
  display: flex;
  justify-content: center;
  align-items: center;
}
h6 {
  line-height: 1.5;
}
.loading-div {
  width: 100%;
  position: absolute;
}
.ele-modal {
  display: flex;
  justify-content: center;
  align-items: center;
}
/deep/.el-select {
  width: 100%;
}
/deep/.el-cascader--medium {
  width: 100%;
}
.el-row {
  padding: 30px;
  min-width: 500px;
}
.el-row-active {
  padding: 30px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

// 主体信息配置
.bg-purple {
  // h标签
  .hLabel {
    margin: 10px 0 20px;
    font-weight: 700;
    &::before {
      content: '';
      display: inline-block;
      vertical-align: top;

      margin-right: 5px;
      height: 23px;
      width: 6px;
      background-color: #1e6ceb;
    }
  }

  .subjectInformationLeft {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    .subjectInformationTitle {
      width: 792px;

      //   background-color: aqua;
      display: flex;
      align-items: center;
      justify-content: center;
      .title {
        margin-right: 46px;
        div {
          color: #666;
          margin: 5px 0 5px;
        }
      }
      .content {
        div {
          color: #000;
          margin: 5px 0 5px;
        }
        .view {
          color: #1e6ceb;
          cursor: pointer;
        }
      }
    }
    .subjectInformationContent {
      display: flex;
      align-items: center;
      justify-content: center;
      .title {
        margin-right: 46px;
        div {
          color: #666;
          margin: 5px 0 5px;
        }
      }
      .content {
        div {
          color: #000;
          margin: 5px 0 5px;
        }
        .view {
          color: #1e6ceb;
          cursor: pointer;
        }
      }
      width: 792px;

      //   background-color: aquamarine;
    }
  }
}

.zfb-purple {
  .zfbHLabel {
    margin: 10px 0 20px;
    font-weight: 700;
    &::before {
      content: url('../../../static/svg/zfbIcon.svg');
      display: inline-block;
      vertical-align: middle;

      margin-right: 5px;
    }
  }

  .ruleForm {
    /deep/ .el-upload--picture-card {
      line-height: 178px;
    }
    .fromSubmitOne {
      .hLabel {
        margin: 10px 0 20px;
        font-weight: 700;
        &::before {
          content: '';
          display: inline-block;
          vertical-align: top;

          margin-right: 5px;
          height: 23px;
          width: 6px;
          background-color: #1e6ceb;
        }
      }
      .subjectTypeSwitch {
        display: flex;
        height: 36px;
        line-height: 36px;
        justify-content: flex-start;
        border-radius: 3%;
        width: 160px;

        background-color: #fff;
        border: 1px solid #d9d9d9;
        text-align: center;
        .enterprise {
          //   overflow: hidden;
          background-color: #fff;
          width: 40%;
        }
        .individuality {
          color: #fff;
          background-color: #289aff;

          width: 60%;
        }
        .active-enterprise {
          width: 40%;
          color: #fff;
          background-color: #289aff;
        }
        .active-individuality {
          color: #606266;
          background-color: #fff;
          width: 60%;
        }
      }
      /deep/.el-form-item__label {
        color: #000;
      }
      /deep/.el-form-item {
        max-width: 737px;
        min-width: 245px;
      }

      span {
        color: #b4b4b4;
      }

      .entryTypeSwitch {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        border-radius: 3%;
        width: 160px;

        background-color: #fff;
        border: 1px solid #d9d9d9;
        text-align: center;
        .enterprise {
          //   overflow: hidden;
          background-color: #fff;
          width: 40%;
        }
        .individuality {
          color: #fff;
          background-color: #289aff;

          width: 60%;
        }
        .active-enterprise {
          width: 40%;
          color: #fff;
          background-color: #289aff;
        }
        .active-individuality {
          color: #606266;
          background-color: #fff;
          width: 60%;
        }
      }
    }
    .fromSubmitTwo {
      .hLabel {
        margin: 10px 0 20px;
        font-weight: 700;
        &::before {
          content: '';
          display: inline-block;
          vertical-align: top;

          margin-right: 5px;
          height: 23px;
          width: 6px;
          background-color: #1e6ceb;
        }
      }
      .subjectTypeSwitch {
        display: flex;
        height: 36px;
        line-height: 36px;
        justify-content: flex-start;
        border-radius: 3%;
        width: 160px;

        background-color: #fff;
        border: 1px solid #d9d9d9;
        text-align: center;
        .enterprise {
          //   overflow: hidden;
          background-color: #fff;
          width: 40%;
        }
        .individuality {
          color: #fff;
          background-color: #289aff;

          width: 60%;
        }
        .active-enterprise {
          width: 40%;
          color: #fff;
          background-color: #289aff;
        }
        .active-individuality {
          color: #606266;
          background-color: #fff;
          width: 60%;
        }
      }
      .ruleForm {
        /deep/.el-form-item__label {
          color: #000;
        }
        /deep/.el-form-item {
          max-width: 737px;
          min-width: 245px;
        }
        /deep/ .el-upload--picture-card {
          line-height: 178px;
        }
        span {
          color: #b4b4b4;
        }
        //正反面
        .positiveAndNegativeIDcards {
          display: flex;
          justify-content: flex-start;
          .positiveIDcards {
            //   margin-right: 50px;
            min-width: 200px;
          }
        }
      }
    }
    .drawer__footer {
      display: flex;
      justify-content: space-between;
    }
  }
}

.wx-purple {
  .wxHLabel {
    margin: 10px 0 20px;
    font-weight: 700;
    &::before {
      content: url('../../../static/svg/wxIcon.svg');
      display: inline-block;
      vertical-align: middle;

      margin-right: 5px;
    }
  }

  .ruleForm {
    .fromSubmitOne {
      .hLabel {
        margin: 10px 0 20px;
        font-weight: 700;
        &::before {
          content: '';
          display: inline-block;
          vertical-align: top;

          margin-right: 5px;
          height: 23px;
          width: 6px;
          background-color: #28c445;
        }
      }

      /deep/.el-range-editor--medium.el-input__inner {
        width: 600px !important;
      }
    }
    /deep/.el-form-item__label {
      color: #000;
    }
    /deep/.el-form-item {
      max-width: 737px;
      min-width: 245px;
    }
    /deep/ .el-upload--picture-card {
      line-height: 178px;
    }
    span {
      color: #b4b4b4;
    }

    .entryTypeSwitch {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      border-radius: 3%;
      width: 160px;

      background-color: #fff;
      border: 1px solid #d9d9d9;
      text-align: center;
      .enterprise {
        //   overflow: hidden;
        background-color: #fff;
        width: 40%;
      }
      .individuality {
        color: #fff;
        background-color: #28c445;

        width: 60%;
      }
      .active-enterprise {
        width: 40%;
        color: #fff;
        background-color: #28c445;
      }
      .active-individuality {
        color: #606266;
        background-color: #fff;
        width: 60%;
      }
    }
    .businessLicenseTime {
      display: flex;

      justify-content: flex-start;
      align-items: center;
    }

    .drawer__footer {
      display: flex;
      justify-content: space-between;
    }
  }
  .fromSubmitTwoWx {
    .hLabel {
      margin: 10px 0 20px;
      font-weight: 700;
      &::before {
        content: '';
        display: inline-block;
        vertical-align: top;

        margin-right: 5px;
        height: 23px;
        width: 6px;
        background-color: #28c445;
      }
    }
    .ruleForm {
      /deep/.el-form-item__label {
        color: #000;
      }
      /deep/.el-form-item {
        max-width: 737px;
        min-width: 245px;
      }
      /deep/ .el-upload--picture-card {
        line-height: 178px;
      }
      span {
        color: #b4b4b4;
      }
      //正反面
      .positiveAndNegativeIDcards {
        display: flex;
        justify-content: flex-start;
        .positiveIDcards {
          margin-right: 50px;
        }
      }
    }
    .drawer__footer {
      display: flex;
      justify-content: space-between;
    }
  }

  .fromSubmitThree {
    display: flex;
    flex-direction: column;
    align-items: center;
    .examine {
      color: #000;
      margin-bottom: 29px;
      font-size: 24px;
    }
    .closePage {
      width: 186px;
      height: 60px;
      border-radius: 43px;
      border: 1px solid #1e6ceb;
      color: #1e6ceb;
      margin-top: 57px;
    }
    .resubmit {
      color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 186px;
      height: 60px;
      border-radius: 43px;
      background: #ff4d4f;
      box-shadow: 0px 4px 4px 0px #ff4d4f;
      margin-top: 57px;
    }
  }
}
.fromSubmitThree {
  display: flex;
  flex-direction: column;
  align-items: center;
  .examine {
    color: #000;
    margin-bottom: 29px;
    font-size: 24px;
  }
  .closePage {
    width: 186px;
    height: 60px;
    border-radius: 43px;
    border: 1px solid #1e6ceb;
    color: #1e6ceb;
    margin-top: 57px;
  }
  .resubmit {
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 186px;
    height: 60px;
    border-radius: 43px;
    background: #ff4d4f;
    box-shadow: 0px 4px 4px 0px #ff4d4f;
    margin-top: 57px;
  }
}
</style>
